package com.example.shushiyunsst.fragment.main.home.child.new_sale.chlid.my_order_list

import android.os.Bundle
import android.view.View
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager.widget.ViewPager
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.library_common.base.BaseFragmentEx
import com.example.shushiyunsst.R
import com.example.shushiyunsst.fragment.main.home.child.new_sale.chlid.my_order_list.chlid.SubMyOrderAllFragment
import com.example.shushiyunsst.fragment.main.home.child.new_sale.chlid.my_order_list.chlid.bean.MY_GOODS_ALL
import com.example.shushiyunsst.fragment.main.home.child.new_sale.chlid.my_order_list.chlid.bean.ON_COMMENT
import com.example.shushiyunsst.fragment.main.home.child.new_sale.chlid.my_order_list.chlid.bean.ON_DELIVERY
import com.example.shushiyunsst.fragment.main.home.child.new_sale.chlid.my_order_list.chlid.bean.ON_SENDING

import com.example.shushiyunsst.util.MY_ORDER_LIST
import com.example.shushiyunsst.util.PAGE_INDEX_OF
import com.google.android.material.tabs.TabLayout

@Route(path = MY_ORDER_LIST)
class MyOrderListFragment : BaseFragmentEx() {

    @JvmField
    @Autowired(name = PAGE_INDEX_OF)
    var pageIndexOf: Int = 0

    override fun getLayoutId(): Any {
        return R.layout.my_order_list_fragment
    }

    private val children = listOf<BaseFragmentEx>(
        SubMyOrderAllFragment.newInstance(MY_GOODS_ALL,R.string.my_order_list_all),
        SubMyOrderAllFragment.newInstance(ON_SENDING,R.string.my_order_list_on_sending),
        SubMyOrderAllFragment.newInstance(ON_DELIVERY,R.string.my_order_list_on_delivering),
        SubMyOrderAllFragment.newInstance(ON_COMMENT,R.string.my_order_list_on_comment),
//        MyOrderListOnPlayingFragment.newInstance(),
//        MyOrderListOnDeliveringFragment.newInstance(),
//        MyOrderListOnCommentFragment.newInstance()
    )

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        val mToolbar: Toolbar = view.findViewById(R.id.mToolbar)
        mToolbar.setTitle(R.string.my_order_list_title)
        mToolbar.setNavigationOnClickListener { onBackPressedSupport() }

        val mTabLayout: TabLayout = view.findViewById(R.id.mTabLayout)
        val mViewPager: ViewPager = view.findViewById(R.id.mViewPager)

        mViewPager.adapter = object : FragmentStatePagerAdapter(
            childFragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
        ) {
            override fun getCount(): Int {
                return children.size
            }

            override fun getItem(position: Int): Fragment {
                return children[position]
            }

            override fun getPageTitle(position: Int): CharSequence? {
                val myOrderListLab = getItem(position) as MyOrderListLab
                return _mActivity.getString(myOrderListLab.title)
            }
        }

        mTabLayout.setupWithViewPager(mViewPager)

        if (pageIndexOf > 0 && pageIndexOf < mTabLayout.tabCount) {
            mViewPager.currentItem = pageIndexOf
        }
    }
}